{% if setting('magic.enable_org', '0') %}

  {% do script(['libs/select2.js', 'app/js/org/org-tree-select/index.js']) %}

  {% set modal = modal|default(null) %}

  {% set colmd = colmd|default(8) %}
  {% set lablecolmd = lablecolmd|default(2) %}
  {% set nocolmd = nocolmd|default(false) %}
  {% set inputClass = inputClass|default('') %}

  {% set currentOrgCode = orgCode|default(app.user.orgCode) %}
  {% set currentOrgTree = data('OrgTree',{orgCode: ('ROLE_SUPER_ADMIN' in app.user.roles) ? null : currentOrgCode }) %}

  {% if withoutFormGroup|default(false) %}
    <select data-role="tree-select" name="orgCode" class="form-control js-org-tree-select {{ inputClass }}">
      <option value={{ currentOrgTree.0.orgCode }}>{{ currentOrgTree.0.name }}</option>
      {% for org in currentOrgTree %}
        <option
          value={{ org.orgCode }} {% if org.orgCode == currentOrgCode %}selected{% endif %}>{% for i in 1..(org.depth-1) if org.depth > 1 %}　{% endfor %}{{ org.name }}</option>
      {% endfor %}
    </select>
  {% else %}
    <div class="form-group {% if modal == 'list' %}controls{% endif %}">
      {% if modal != 'list' %}
      <label
        class="{% if not nocolmd %} col-md-{{ lablecolmd }}{% endif %} control-label">{{ 'site.org'|trans }}</label>
      <div class="{% if not nocolmd %} col-md-{{ colmd }} {% endif %}  controls">
        {% endif %}

        <select data-role="tree-select" name="orgCode" class="form-control js-org-tree-select {{ inputClass }}">
          <option value={{ currentOrgTree.0.orgCode }}>{{ currentOrgTree.0.name }}</option>
          {% for org in currentOrgTree %}
            <option
              value={{ org.orgCode }} {% if org.orgCode == currentOrgCode %}selected{% endif %}>{% for i in 1..(org.depth-1) if org.depth > 1 %}　{% endfor %}{{ org.name }}</option>
          {% endfor %}
        </select>

        {% if modal != 'list' %}
      </div>
      {% endif %}
    </div>
  {% endif %}

{% endif %}
